Skip to content

Address flake8 error lambda functions (E731) - #78

Closed
bobleesj wants to merge 1 commit into
diffpy:cookiefrom
bobleesj:cookie-flake8-E731
Closed

bobleesj wants to merge 1 commit into
diffpy:cookiefrom
bobleesj:cookie-flake8-E731

Conversation

@bobleesj

@bobleesj bobleesj commented Aug 21, 2024 •

Copy link
Copy Markdown

Tests pass:

imac@imacs-iMac diffpy.srfit % python -m diffpy.srfit.tests.run
WARNING:diffpy.srfit.tests:No module named 'sas', SaS tests skipped.
WARNING:diffpy.srfit.tests:Cannot import pyobjcryst, pyobjcryst tests skipped.
WARNING:diffpy.srfit.tests:Cannot import diffpy.srreal, PDF tests skipped.
......ssss................................sssssssssss....ssssss...........................sss..s..............
----------------------------------------------------------------------
Ran 110 tests in 0.170s

OK (skipped=25)

@bobleesj bobleesj left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review @sbillinge

self._invertor.y = iq
self._invertor.err = diq
c, c_cov = self._invertor.invert_optimize()
calculate_pr = lambda x: self._invertor.pr(c, x)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using lambda functions that are short and concise actually increase readability... Hence adding # noqa: E731 as well.

@bobleesj

Copy link
Copy Markdown
Author

This is the last PR for flake8. We shall implement CI/pre-commit very soon.

@bobleesj
bobleesj marked this pull request as ready for review August 21, 2024 02:16

@sbillinge sbillinge left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comments. I am not a fan of lots of lambdas. I like them for sort keys and things like that where they are much more readable having the logic in place (not assigned) but elsewhere I think they rarely make things clearer than clearly written code with explicit functions and well chosen function names

excluded_types = set((opmod.CustomOperator, opmod.UFuncOperator))
# check if opmod member should be wrapped as OperatorBuilder
is_exported_type = lambda cls: (
is_exported_type = lambda cls: ( # noqa: E731

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't find this very readable. We can't do better here?

Comment thread src/diffpy/srfit/fitbase/fithook.py Resolved
self._invertor.err = diq
c, c_cov = self._invertor.invert_optimize()
calculate_pr = lambda x: self._invertor.pr(c, x)
calculate_pr = lambda x: self._invertor.pr(c, x) # noqa: E731

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one also better to put it in the map directly? Or maybe as an explicit function

eq.x.setValue(x)
eq.sigma.setValue(sigma)
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2))
f = lambda x, sigma: sqrt(e ** (-0.5 * (x / sigma) ** 2)) # noqa: E731

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here in the tests they are quite readable and not doing much harm so I suggest leaving with noqa

@bobleesj

Copy link
Copy Markdown
Author

Please see comments. I am not a fan of lots of lambdas. I like them for sort keys and things like that where they are much more readable having the logic in place (not assigned) but elsewhere I think they rarely make things clearer than clearly written code with explicit functions and well chosen function names

Noted. I will address these later in the afternoon.

@bobleesj

Copy link
Copy Markdown
Author

@sbillinge I will close this PR and make separate PRs address each file or so. I will refer back to your in-line comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants